package com.woniu.his.app.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.app.client.AppHistoryClient;
import com.woniu.his.app.client.param.*;
import com.woniu.his.app.client.result.*;
import com.woniu.his.app.service.service.RegistrationService;
import com.woniu.his.app.service.service.dto.AppDrugItemDto;
import com.woniu.his.app.service.service.dto.AppHistoryRegDto;
import com.woniu.his.app.service.service.dto.RegHistoryDto;
import com.woniu.his.app.service.service.dto.RegistrationFeeDto;
import com.woniu.his.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@Slf4j
@RequestMapping("/app")
public class AppHistoryApiImpl implements AppHistoryClient {

    @Resource
    private RegistrationService registrationService;


    @Override
    public Result demo(DemoParam param) {
        return null;
    }


    /**
     * @Description: 根据身份证查询挂号历史信息
     * @Param:
     * @return:
     * @Date: 2022/11/26
     */
    @Override
    public Result<List<RegHistoryResult>> listAllRegistration(String identificationNo) {

        log.info("身份证号：{}" + identificationNo);

        List<RegHistoryDto> list = registrationService.listAllRegistration(identificationNo);
        List<RegHistoryResult> regHistoryResults = BeanUtil.copyToList(list, RegHistoryResult.class);
        return Result.getInstanceList(RegHistoryResult.class).setMsg("历史挂号信息查询成功").setData(regHistoryResults);
    }

    /**
     * @Description: 根据病历id查询某次挂号中（检查/拿药）费用（大项 大类）
     * @Param: dx
     * @return:
     * @Date: 2022/11/26
     */
    @Override
    public Result<List<AppHistoryRegResult>> listFee(Long caseHistoryId) {

        log.info("病历id：{}", caseHistoryId);

        List<AppHistoryRegDto> appHistoryRegDto = registrationService.listFee(caseHistoryId);
        List<AppHistoryRegResult> results = BeanUtil.copyToList(appHistoryRegDto, AppHistoryRegResult.class);
        return Result.getInstanceList(AppHistoryRegResult.class).setMsg("历史收费信息查询成功").setData(results);
    }


    /**
     * @Description:  查询某次挂号每种药费用（中药 草药（小项） 根据处方id
     * @Param:
     * @return:
     * @Date: 2022/11/26
     */
    @Override
    public Result<List<AppDrugItemResult>> listFeeDetail(Long prescriptionId, String type) {

        log.info("处方id: {}" + prescriptionId,"类型: {}"+type);

        List<AppDrugItemDto>  list= registrationService.listFeeDetail(prescriptionId,type);
        List<AppDrugItemResult> results = BeanUtil.copyToList(list, AppDrugItemResult.class);
        return Result.getInstanceList(AppDrugItemResult.class).setMsg("历史收费信息查询成功").setData(results);
    }


    /**
     * @Description:  查询检查检验结果
     * @Param:
     * @return:
     * @Date: 2022/11/26
     */
    @Override
    public Result<AppCheckTestResult> getResult(Long id) {
        log.info("检查id: { }" + id);
        //直接调用dms 接口 ??
        return null;
    }

    /**
     * 获取挂号费用 退号情况
     * @param caseHistoryId
     * @return
     */
    @Override
    public Result<RegistrationFeeResult> getRegistrationFeeByCase(Long caseHistoryId) {

        log.info("病历id: { }" + caseHistoryId);
        RegistrationFeeDto registrationFeeDto=  registrationService.getRegistrationFeeByCase(caseHistoryId);
        RegistrationFeeResult result= BeanUtil.copyProperties(registrationFeeDto,RegistrationFeeResult.class);
        return Result.getInstance(RegistrationFeeResult.class).setData(result).setMsg("挂号费用查询成功");
    }


    @Override
    public Result<List<AppDeptDescriptionResult>> getDeptDescription() {
        return null;
    }
}
